package com.aplikata.evok.ui;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.aplikata.bo.User;
import com.aplikata.constants.Constants;
import com.aplikata.evok.service.EvokUserService;
import com.aplikata.ui.LoginBean;
import com.aplikata.util.FacesUtil;

/**
 * @ClassName: MLoginBean
 * @Description: TODO
 * @author Huyun
 * @date 26. 4. 2012. 14:30:56
 */

@ManagedBean(name = "mloginBean")
@RequestScoped
public class MLoginBean extends LoginBean {

	@ManagedProperty(value = "#{evokUserService}")
	private EvokUserService evokUserService;
	public static Log log;

	public MLoginBean() {
		log = LogFactory.getLog(MLoginBean.class);
	}

	public String loginEvokMobile() {
		try {
			return evokUserService.submitMobileLogin(this.getUser().getUserName(), this.getUser().getUserPwd());
		} catch (Exception e) {
			FacesUtil.addActionListenerException(e, log);
		}
		return null;
	}

	public String logout() {
		FacesUtil.setManagedBeanInSession(Constants.SESSION_USER, null);
		FacesUtil.setManagedBeanInSession(Constants.SESSION_DOMAIN, null);
		this.setUser(new User());

		return "pm:main";
	}

	public EvokUserService getEvokUserService() {
		return evokUserService;
	}

	public void setEvokUserService(EvokUserService evokUserService) {
		this.evokUserService = evokUserService;
	}

}
